package com.cms.core.foundation;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * @author laolang
 * @version 1.0.0
 * @ClassName result
 */
@Getter
@Setter
public class Result<T  extends Serializable> implements Serializable {

    private int code;
    private String msg;
    private T data;

    public Result(int code){
        this.code = code;
    }
    public Result(String msg){

        this.code = code;
        this.msg = msg;
    }
    public Result(int code,String msg){
        this.code = code;
        this.msg = msg;
    }
    public Result(int code,String msg,T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public Result(int code,T data){
        this.code = code;
        this.data = data;
    }


    /**
     * 定义成功200
     * @param <w>
     * @return
     */
    public static <W extends Serializable> Result<W> success(){
        return new Result<>(200,"成功！");
    }
    public static <W extends Serializable> Result<W> success(W data){
        return new Result<>(200,data);
    }
    public static <W extends Serializable> Result<W> success(int code,W data){
        return new Result<>(code,data);
    }
    public static <W extends Serializable> Result<W> success(int code,String msg,W data){
        return new Result<>(code,msg,data);
    }
    public static <W extends Serializable> Result<W> success(String msg){
        return new Result<>(200,msg);
    }

    //返回失败结果集
    public static <W extends Serializable> Result<W> error(){
        return new Result<>(500);
    }

    public static <W extends Serializable> Result<W> error(int code,String msg){
        return new Result<>(code,msg);
    }

    public static <W extends  Serializable> Result<W> error(String msg){
        return  new Result<>(msg);
    }



}
